# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo6.06
# Description:
# Author:       $赵怡蕾
# Date:         2019/2/15
#-------------------------------------------------------------------------------

# 定义一个字典
persons1 = {"Name":"Bill","age":30,"fullName":["Bill","Gates"]}
# 对persons1进行浅层复制
persons2 = persons1.copy()
# 输出persons1
print("persons1",persons1)
# 输出persons2
print("persons2",persons2)
print("-------浅层复制-------")
print("-------修改第一层元素-------")
# 修改persons2中key为"age"的值
persons2['age'] = 54
# 运行结果：presons1 {'Name': 'Bill', 'age': 30, 'fullName': ['Bill', 'Gates']}
print("presons1",persons1)
# 运行结果：presons2 {'Name': 'Bill', 'age': 54, 'fullName': ['Bill', 'Gates']}
print("presons2",persons2)
print("-------修改第二层元素-------")
# 修改persons2的第2层数据（字符串列表中的第2个元素)
persons2["fullName"][1] = "Clinton"
# 运行结果：persons1 {'Name': 'Bill', 'age': 30, 'fullName': ['Bill', 'Clinton']}
print("persons1",persons1)
# 运行结果：persons2 {'Name': 'Bill', 'age': 54, 'fullName': ['Bill', 'Clinton']}
print("persons2",persons2)
print("-------深层复制-------")
from copy import deepcopy
persons1 = {"Name":"Bill","age":30,"fullName":["Bill","Gates"]}
# persons2为浅层复制的字典
persons2 = persons1.copy()
# persons3为深层复制的字典
persons3 = deepcopy(persons1)
# 修改原字典的第2层元素
persons1["fullName"][1] = "Clinton"
# 运行结果：persons1 {'Name': 'Bill', 'age': 30, 'fullName': ['Bill', 'Clinton']}
print("persons1",persons1)
# 运行结果：persons2 {'Name': 'Bill', 'age': 30, 'fullName': ['Bill', 'Clinton']}
print("persons2",persons2)
# 运行结果：persons3 {'Name': 'Bill', 'age': 30, 'fullName': ['Bill', 'Gates']}
print("persons3",persons3)